#!/usr/bin/env bash
#
check_ipv6_iptables_if_need() {
  # 检查 IPv6
  use_ipv6=$(get_config USE_IPV6)
  subnet_ipv6=$(get_config DOCKER_SUBNET_IPV6)
  if [[ "${use_ipv6}" == "1" ]]; then
    if ! ip6tables -t nat -L | grep "${subnet_ipv6}" >/dev/null; then
      ip6tables -t nat -A POSTROUTING -s "${subnet_ipv6}" -j MASQUERADE
    fi
  fi
}

get_docker_compose_cmd_line() {
  ignore_db="$1"
  cmd="docker-compose "
  cmd="${cmd} -f ./compose/docker-compose-network.yml"
  cmd="${cmd} -f ./compose/docker-compose-zookeeper.yml"
  cmd="${cmd} -f ./compose/docker-compose-elasticsearch.yml"
  cmd="${cmd} -f ./compose/docker-compose-mysql.yml"
  cmd="${cmd} -f ./compose/docker-compose-mongodb.yml"
  cmd="${cmd} -f ./compose/docker-compose-nacos.yml"
  cmd="${cmd} -f ./compose/docker-compose-redis.yml"
  cmd="${cmd} -f ./compose/docker-compose-canal.yml"
  cmd="${cmd} -f ./compose/docker-compose-canal-admin.yml"
  cmd="${cmd} -f ./compose/docker-compose-rocketmq.yml"
  cmd="${cmd} -f ./compose/docker-compose-portainer.yml"
  cmd="${cmd} -f ./compose/docker-compose-xxljob.yml"
  cmd="${cmd} -f ./compose/docker-compose-spring-admin.yml"
  cmd="${cmd} -f ./compose/docker-compose-seata.yml"
  cmd="${cmd} -f ./compose/docker-compose-zipkin.yml"
  cmd="${cmd} -f ./compose/docker-compose-sentinel.yml"
  cmd="${cmd} -f ./compose/docker-compose-kibana.yml"
  cmd="${cmd} -f ./compose/docker-compose-kafka.yml"
  echo "${cmd}"
}

get_docker_compose_services() {
  ignore_db="$1"
  services=""
  services+=" zookeeper"
  services+=" elasticsearch"
  services+=" mysql"
  services+=" mongodb"
  services+=" nacos"
  services+=" redis"
  services+=" canal"
  services+=" canal-admin"
  services+=" rmqnamesrv"
  services+=" rmqbroker"
  services+=" rmqconsole"
  services+=" portainer"
  services+=" xxljob"
  services+=" spring-admin"
  services+=" seata"
  services+=" zipkin"
  services+=" sentinel"
  services+=" kibana"
  services+=" kafka"
  echo "${services}"
}
